	package model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Query;
import javax.persistence.Transient;

import database.SingleEntityManagerFactory;


@Entity
public class SdkFile extends Model {


	private String nmFile;

	private String dsVersion;

	private String dtInsert;

	private String dtUpdate;

	private String nmUserUpd;
	
	private List<SdkDynMapperXsd> sdkDynMapperXsds;
	
	@Lob
	private byte[] flFile;
	
	
	@Id
	@GeneratedValue
	@Override
	@Column(name="CDFILE")
	public int getId() {
		// TODO Auto-generated method stub
		return super.getId();
	}

	@Override
	public void setId(int id) {
		// TODO Auto-generated method stub
		super.setId(id);
	}

	public String getNmFile() {
		return nmFile;
	}

	public void setNmFile(String nmFile) {
		this.nmFile = nmFile;
	}

	public String getDsVersion() {
		return dsVersion;
	}

	public void setDsVersion(String dsVersion) {
		this.dsVersion = dsVersion;
	}

	public String getDtInsert() {
		return dtInsert;
	}

	public void setDtInsert(String dtInsert) {
		this.dtInsert = dtInsert;
	}

	public String getDtUpdate() {
		return dtUpdate;
	}

	public void setDtUpdate(String dtUpdate) {
		this.dtUpdate = dtUpdate;
	}

	public String getNmUserUpd() {
		return nmUserUpd;
	}

	public void setNmUserUpd(String nmUserUpd) {
		this.nmUserUpd = nmUserUpd;
	}

	public byte[] getFlFile() {
		return flFile;
	}

	public void setFlFile(byte[] flFile) {
		this.flFile = flFile;
	}
	
	
	
	@OneToMany (mappedBy="cdFile")
	public List<SdkDynMapperXsd> getSdkDynMapperXsds() {
		return sdkDynMapperXsds;
	}

	public void setSdkDynMapperXsds(List<SdkDynMapperXsd> sdkDynMapperXsds) {
		this.sdkDynMapperXsds = sdkDynMapperXsds;
	}

	@Transient
	public SdkFile getSdkFile (int value)
	{
		EntityManager session = SingleEntityManagerFactory.getInstance().createEntityManager();
		Query query = session.createQuery("FROM SdkFile where cdfile = :a"); 
		query.setParameter("a", value); 
		List<SdkFile> list = query.getResultList();
		if(list.isEmpty())
		{
			return null;

		}
		else
		{
			return list.get(0);
		}
	}
	
	
	

}
